package com.shire.shire_interface.controller.rule;

import com.alibaba.fastjson.JSONObject;
import com.shire.shire_interface.common.bin.Response;
import com.shire.shire_interface.controller.BaseController;
import com.shire.shire_interface.model.rule.WxRuleRecord;
import com.shire.shire_interface.model.rule.WxRuleRecordExample;
import com.shire.shire_interface.service.rule.WxRuleRecordService;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import javax.servlet.http.HttpSession;
import java.util.List;

//@Api(tags = "群管理 自动踢人")
@RestController
@RequestMapping("/rule")
public class WxRuleRecordController extends BaseController {

    @Resource
    private WxRuleRecordService wxRuleRecordService;

//    @ApiOperation(value = "触发记录 csId")
    @ResponseBody
    @PostMapping("/recordHistory")
    public Response recordHistory(@RequestBody JSONObject jsonObject, HttpSession session){
        Response response = new Response();
        try {

            Integer csId = jsonObject.getInteger("csId");
            if (!checkLoginUserByCsId(session, csId)){
                response.error("请登录！");
                response.setCode(501);
                return response;
            }
            WxRuleRecordExample example = new WxRuleRecordExample();
            example.createCriteria().andCsidEqualTo(csId);
            addPageParamToExample(jsonObject, example);
            List<WxRuleRecord> wxRuleRecords = wxRuleRecordService.selectByExample(example);

            response.setData(wxRuleRecords);
            response.success("成功");
        } catch (Exception e) {
            response.error("失败");
            e.printStackTrace();
        }
        return response;
    }
}
